<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>我的工作-云校通-教师</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<script src="<%=basePath %>/js/calendar-xtbg.js"></script>
<body ontouchstart style="background: #fff;">
<div class="weui_tab tab-bottom">
	<div class="weui-header bg-blue"> 
  		<div class="weui-header-left"> <a onclick="back()" href="javascript:" class="icon icon-109 f-white">返回</a> </div>
    	<h1 class="weui-header-title">${term.termName }</h1>
    </div>
	<div class="weui_tab_bd">
		<div class="weui_tab ltbg-content" id="tab3">
            <div class="weui_navbar">
                <div class="weui_navbar_item" id="dwspList">
                    	未回评
                </div>
                <div class="weui_navbar_item" id="wyspList">
                    	已回评
                </div>
            </div>
            <div class="weui_tab_bd">
                
	            <div class="weui_panel weui_tab_bd_item mt0">
		            <div class="weui_panel_bd">
		            	<div class="weui_cells weui_cells_access mt0" id="dListTable">
		            	
		            	</div>
		            </div>
		            <div class="dropload-down">
					    <div class="loadData dropload-hasData">点击加载更多数据...</div>
					</div>
	            </div>
		        
	            <div class="weui_panel weui_tab_bd_item mt0">
		            <div class="weui_panel_bd">
		                <div class="weui_cells weui_cells_access mt0" id="yListTable">
		            	
		            	</div>
		            </div>
		            <div class="dropload-down">
					    <div class="loadData dropload-hasData">点击加载更多数据...</div>
					</div>
	            </div>
	            
	            <script id="office-table-template" type="text/x-handlebars-template">
					{{#each rows}}
					<a class="weui_cell weui_media_box weui_media_text" href="<%=basePath%>${user.currUrl}/week/comment/detail/{{id}}?sid={{studentId}}">                        
						<div class="weui_cell_bd weui_cell_primary">                    		
							<h4 class="weui_media_title">{{studentName}}同学的第{{weekNo}}周点评</h4>                    		
							<p class="weui_media_desc">{{teacherCommentContent}}</p>                    		
							<p class="weui_media_desc mt10">发布时间：{{dateFormat teacherCommentTime}}</p>                		
						</div>                		
						<span class="weui_cell_ft"></span>            		
					</a>
					{{/each}}
				</script>
            </div>
        </div>
	</div>
</div>
</body>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script>
var isLoadFinished = false;
var d_page = 1, y_page = 1, rows = 10;
$(function() {
	$('#tab3').tab({
		defaultIndex: 0,
		activeClass: "tab-blue "
	});
	$("#wyspList").click(function() {
		if(!isLoadFinished) loadMyWork(2, 'yListTable');
	})
	$(".dropload-down").on("click", ".dropload-hasData", function() {
		var id = $(this).closest(".weui_tab_bd_item").find(".weui_cells").attr("id");
		if(id == 'dListTable') {
			loadMyWork(1, 'dListTable');
		}else if(id == 'yListTable') {
			loadMyWork(2, 'yListTable');
		}
	})		
	loadMyWork(1, 'dListTable');
})

function loadMyWork(isFinished, id) {
   var params = {
	    status: isFinished,
		page: isFinished == 0 ? d_page : y_page,
		rows: rows	   
   }
   if("${user.roleType}" == 0) {
	   params.parentId = "${user.parent.id}";
   }else {
	   params.studentId = "${studentId}";
   }
   $.ajax({
     	url : basePath + "${user.currUrl}/week/comment/page",
 		type : "post",
 		dataType : "json",
 		data : params,
        success: function(data){
        	if(data.rows.length == 0 || params.page*params.rows >= data.total) {// 如果没有数据
        		$("#" + id).closest(".weui_tab_bd_item").find('.loadData').removeClass("dropload-hasData").addClass("dropload-noData").html("没有更多数据了");
            	if(data.rows.length == 0) return;
            }
        	isFinished == 1 ? d_page += 1 : y_page += 1
       	  	loadOfficeHtml(data,isFinished);
         },
         error: function(xhr, type){
             
         }
     });
}
function loadOfficeHtml(data,isFinished){
	var myTemplate = Handlebars.compile($("#office-table-template").html());
	Handlebars.registerHelper("equal", function(v1,v2,options) {
		if(v1 == v2) {
			//满足添加继续执行
			return options.fn(this);
		}else {
			//不满足条件执行{{else}}部分
			return options.inverse(this);
		}
	});
	Handlebars.registerHelper("feedbackFormat", function(v1,v2,options) {
		if(v1) return "";
		return "<a href='javascript:void(0)' onclick='feedback("+v2+")' class='wdgz-list-link-fk'>反馈</a>";
	});
	Handlebars.registerHelper("dateFormat", function(v1) {
		return getTime(v1, "yyyy-MM-dd hh:mm:ss");
	});
	if(isFinished == 1) $('#dListTable').append(myTemplate(data));
	else $('#yListTable').append(myTemplate(data));
}
</script>
</html>